package com.Test;

import com.alibaba.druid.pool.DruidDataSource;
import com.config.SpringConfig;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.sql.SQLException;

public class SpringTest {
    @Test
    public void xmlIoc(){
        ClassPathXmlApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring.xml");
        Object user = applicationContext.getBean("user");
        System.out.println(user);
        applicationContext.close();
    }
    @Test
    public void classIoc(){
        AnnotationConfigApplicationContext applicationContext=new AnnotationConfigApplicationContext(SpringConfig.class);
        Object user = applicationContext.getBean("user");
        System.out.println(user);
        applicationContext.close();
    }
    @Test
    public void xmlDruid() throws SQLException {
        ClassPathXmlApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring.xml");
        DruidDataSource druid = (DruidDataSource) applicationContext.getBean("druid");
        System.out.println(druid.getConnection());
        applicationContext.close();
    }
    @Test
    public void classDruid() throws SQLException {
        AnnotationConfigApplicationContext applicationContext=new AnnotationConfigApplicationContext(SpringConfig.class);
        DruidDataSource druid = (DruidDataSource) applicationContext.getBean("druid");
        System.out.println(druid.getConnection());
        applicationContext.close();
    }
}
